// Author	: damphat@gmail.com
// Created	: 01/12/2008

#include "vn/Math.hpp"

float round(float v) {
	return floor(v + (float)0.5);
}

double round(double v) {
	return floor(v + (double)0.5);
}

float round(float v, int digits) {
	float a = pow((float)10, digits);
	return floor(v * a + (float)0.5) / a;
}

double round(double v, int digits) {
	double a = pow((double)10, digits);
	return floor(v * a + (double)0.5) / a;
}

float log(float v, float  base) {
	return log(v) / log(base);
}

double log(double v, double base) {
	return log(v) / log(base);
}

float  truncate(float  v) {
	return v < 0? ceil(v) : floor(v);
}

double truncate(double v) {
	return v < 0? ceil(v) : floor(v);
}

float  truncate(float  v, int digits) {
	float a = pow((float)10, digits);
	return truncate(v * a) / a;
}

double truncate(double v, int digits) {
	double a = pow((double)10, digits);
	return truncate(v * a) / a;
}


const double Math::PI	= 3.14159265358979323846;
const double Math::PI_2	= 1.57079632679489661923;
const double Math::PI_4	= 0.785398163397448309616;
const double Math::E	= 2.71828182845904523536;
